﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace AfterlifeLib.Levels
{
    /// <summary>
    /// Een layer voor collision data
    /// </summary>
    public class CollisionLayer : Layer
    {
        public CollisionLayer() : base() { }

        public CollisionLayer(int[,] values)
            : base(values)
        {

        }

        public CollisionLayer(int width, int height)
            : base(width, height)
        {
            TotalFill(0);
        }

        public void SetValue(int x, int y, bool walkable)
        {
            if (walkable)
                Values[y, x] = 0;
            else
                Values[y, x] = 1;
        }

        public void SwitchValue(int x, int y)
        {
            if (Values[y, x] == 0)
                Values[y, x] = 1;
            else
                Values[y, x] = 0;
        }

        public bool InCollisionTile(int x, int y)
        {
            return Values[y, x] == 1;
        }

        public void EditorDraw(SpriteBatch spriteBatch, Camera2D camera, Texture2D collisionTile)
        {
            spriteBatch.Begin();
            {
                for (int x = 0; x < Width; x++)
                {
                    for (int y = 0; y < Height; y++)
                    {
                        if (Values[y, x] == 1)
                        {
                            spriteBatch.Draw(
                                collisionTile,
                                new Rectangle(
                                x * Level.TileDrawWidth - camera.IntX,
                                y * Level.TileDrawHeight - camera.IntY,
                                Level.TileDrawWidth,
                                Level.TileDrawHeight),
                            null,
                            Color.White);
                        }
                    }
                }
            }
            spriteBatch.End();
        }
    }
}
